package frsf.cidisi.exercise.proyectoia.situationcalculus;

import frsf.cidisi.faia.state.EnvironmentState;

public class StateMapa extends EnvironmentState {

	
	private int[][] world;
    private int[] agentPosition;
	
	
    public StateMapa() {
        
    	world = new int[3][3];
        this.initState();
    }

    @Override
    public void initState() {
    	// Escenario 1
    	//this.setAgentPosition(new int[] {0, 0});

    	// Escenario 2
    	//this.setAgentPosition(new int[] {0, 2});
    	
    	// Escenario 3
    	this.setAgentPosition(new int[] {1, 1});
    	
        for (int row = 0; row < world.length; row++) {
            for (int col = 0; col < world.length; col++) {
                world[row][col] = DronePerception.DESCONOCIDO;
            }
        }

        // Escenario 1
        /*world[0][0] = DronePerception.PERSONAS;
        world[0][1] = DronePerception.PERSONAS;
        world[1][0] = DronePerception.PERSONAS;
        world[1][1] = DronePerception.PERSONAS;
        world[1][2] = DronePerception.VICTIMARIO;
        world[2][0] = DronePerception.PERSONAS;
        world[2][1] = DronePerception.PERSONAS;*/
        
        // Escenario 2
        /*world[0][0] = DronePerception.PERSONAS;
        world[0][1] = DronePerception.PERSONAS;
        world[0][2] = DronePerception.PERSONAS;
        world[1][0] = DronePerception.PERSONAS;
        world[1][1] = DronePerception.PERSONAS;
        world[1][2] = DronePerception.PERSONAS;
        world[2][0] = DronePerception.VICTIMARIO;
        world[2][1] = DronePerception.PERSONAS;*/
        
        // Escenario 3
        world[2][2] = DronePerception.VICTIMARIO;
    }
    
    public String toString() {
        String str = "";

        str = str + "[ \n";
        for (int row = 0; row < world.length; row++) {
            str = str + "[ ";
            for (int col = 0; col < world.length; col++) {
                str = str + this.convertCell(world[row][col]) + " ";
            }
            str = str + "]\n";
        }
        str = str + " ]";

        return str;
    }
    
    private String convertCell(int p) {
        String r = "";

        if (p == DronePerception.PERSONAS) {
            r = "P";
        } else if (p == DronePerception.VICTIMARIO) {
            r = "V";
        } else if (p == DronePerception.DESCONOCIDO) {
            r = " ";
        }

        return r;
    }


 
    
    //TODO: Complete this section with agent-specific methods
    // The following methods are agent-specific:
    

	public int[][] getWorld() {
		return world;
	}

	public void setWorld(int[][] world) {
		this.world = world;
	}

	public int[] getAgentPosition() {
		return agentPosition;
	}

	public void setAgentPosition(int[] agentPosition) {
		this.agentPosition = agentPosition;
	}
	
	public int getEsquina(int fila, int columna){
		return world[fila][columna];
	}
	
	public int[] getVictimario(){
		int[] pos = {-1,-1};
		for(int i=0; i<3; i++)
        	for(int j=0; j<3; j++)
        		if(world[i][j] == DronePerception.VICTIMARIO)
        		{
        			pos[0] = i;
        			pos[1] = j;
        		}
        			
        return pos;
	}

    
}
